import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { createElement } from 'react';
import dynamic from 'dva/dynamic';

var modelNotExisted = function modelNotExisted() {
  var app = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var model = arguments.length > 1 ? arguments[1] : undefined;
  return !(app._models || []).some(function (_ref) {
    var namespace = _ref.namespace;
    return namespace === model.substring(model.lastIndexOf('/') + 1);
  });
}; // wrapper of dynamic


export var dynamicWrapper = function dynamicWrapper(app, _models, _component) {
  return dynamic({
    app: app,
    models: function models() {
      return _models.filter(function (model) {
        return modelNotExisted(app, model);
      }).map(function (m) {
        return import("../../models/".concat(m, ".js"));
      }) || [];
    },
    // add routerData prop
    component: function component() {
      return (// if (!routerDataCache) {
        //   routerDataCache = getRouterData(app);
        // }
        _component().then(function (raw) {
          var Component = raw.default || raw;
          return function (props) {
            return createElement(Component, _objectSpread({}, props));
          };
        })
      );
    }
  });
};